<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;


class LoginController extends Controller
{
     public function login()
    {
        $data = [];
        return view('4s.login',compact('data'));
    }

    public function loginDo(Request $request)
    {
        $rs['status'] = 'danger';
        $data['phone']   = $request->phone;
        $data['truename'] = $request->truename;
        $wechat_user     =  session('wechat.oauth_user.default');             
       
        $data['openid']   = $wechat_user->id;
        $data['nickname'] = $wechat_user->nickname;
        $data['avatar']   = $wechat_user->avatar;
        $data['role_code'] = 2; //1 管理员 2 技师
        User::updateOrCreate(['openid'=>$data['openid']],$data);

        $rs['status'] = 'success'; 
        $rs['msg'] = '账号信息已绑定成功。可以关闭此页面。';            
        return back()->with('rs',$rs);

    }
    
}
